#include <iostream>
#include <string>
#include <queue>
#include <map>
#define maxn 11
using namespace std;
// #define ONLINE_GUDGE

using node = pair<string, int>;
#define str first
#define step second

string a, b;
string original[maxn];
string translated[maxn];
int n, ans;
map<string, int> ma;

string trans(const string& str, int i, int j) {
	string ans = "";
	if (i + original[j].length() > str.length())
		return ans;

	for (int k = 0; k < original[j].length(); k++)
		if (str[i + k] != original[j][k])
			return ans;

	ans = str.substr(0, i);
	ans += translated[j];
	ans += str.substr(i + original[j].length());
	return ans;
}

void bfs()
{
	queue<node> q;
	q.push({ a,0 });
	while (!q.empty())
	{
		node u = q.front();
		q.pop();
		string temp;

		if (ma.count(u.str) == 1)
			continue;

		if (u.str == b) {
			ans = u.step;
			break;
		}

		ma[u.str] = 1;
		for (int i = 0; i < u.str.length(); i++) {
			for (int j = 0; j < n; j++) {
				temp = trans(u.str, i, j);
				if (temp != "") {
					q.push({ temp, u.step + 1 });
				}
			}
		}
	}
    
	if (ans > 10 || ans == 0)
		cout << "NO ANSWER!\n";
	else
		cout << ans << "\n";

}

int main()
{
    #ifdef ONLINE_JUDGE

    #else
    freopen("./in.txt","r",stdin);
    #endif
    ios::sync_with_stdio(false);   
	cin.tie(0);

	cin >> a >> b;
	while (cin >> original[n] >> translated[n])
		n++;
	bfs();
	return 0;
}